package com.zk.atm.utils;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {

	public static Connection conn=null;
	
	public static Connection getDBConnection() throws Exception{
		if(conn==null||conn.isClosed()){
			try {
				Class.forName("oracle.jdbc.driver.OracleDriver") ;
				String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl" ;
				conn = DriverManager.getConnection(url, "atmp", "atmp") ;
				//System.out.println(conn);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return conn;
	}
	
	public static void closeDBConn(Connection conn) throws Exception{
		if(conn!=null){
			try {
				conn.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		try {
			System.out.println(DBConnection.getDBConnection());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
